#!/bin/sh

# "configurehere" for system-specific subdirectories of ampl/solvers
# Originally written by David M. Gay at Sandia National Labs, where it
# was Approved for Unclassified-Unlimited release: SAND Number 2005-7813P
# Modified to remove a now unnecessary test.

## Invoke ./configurehere
## (no args) to create makefile from makefile.u for compiling amplsolver.a
## in this directory.  Then invoke "make -r" to compile amplsolver.a
## Specify CC before ./configurehere to adjust the CC setting in makefile.
## Specify CFLAGS before ./configurehere to adjust CFLAGS setting in the
## makefile.  CFLAGS may be further adjusted by tests done below.

if [ -f makefile ]; then make clean; rm makefile; fi

case $CFLAGS in '') CFLAGS='-O';; esac

# For Cygwin or MinGW/MSYS...
EXEmodify=""
case $WINDIR in C:*)
	case $CC in "") CC=gcc;; esac
	EXEmodify=";s!a\\.out!a.exe!";;
	esac

${CC=cc} -c xectim.c 2>/dev/null && rm xectim.o || CFLAGS="$CFLAGS -DNO_RUSAGE"

SC="s!^CC = cc!CC = $CC!$EXEmodify"

case `uname -m` in
	alpha) if cc --version 2>/dev/null | sed 1q | grep -q GCC
		then CFLAGS="$CFLAGS -mieee"
		else CFLAGS="$CFLAGS -ieee_with_no_inexact"
		fi;;
	esac

case `uname -s` in
	AIX) CFLAGS="$CFLAGS -qnomaf";;
	Darwin) if cc -c -D_NONSTD_SOURCE arithchk.c 2>/dev/null; then
			CFLAGS="$CFLAGS -D_NONSTD_SOURCE";
			rm arithchk.o; fi;;
	SunOS) case `uname -i 2>/dev/null` in
		i386)  SC="$SC;s/^a = \\\\$/a = fpsetprec.s \\\\/";;
		i86pc) SC="$SC;s/^a = \\\\$/a = fpsetprec64.s \\\\/";;
		esac;;
	CYGWIN_*) case $EXEmodify in "") SC="$SC;s/a\.out/a.exe/";; esac;;
	esac

case $CFLAGS in -O);; *) SC="$SC;s@^CFLAGS = -O@CFLAGS = $CFLAGS@";; esac

sed "$SC" makefile.u >makefile
